const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            page: {
                value1: '',
                PageNumber: 1, //页码
                RowAmount: 20,
                Condition: window.btoa(unescape(encodeURIComponent("%%,%%,%%"))),
                ExtensionCondition: window.btoa(unescape(encodeURIComponent(" and  natural_resources_bsm_usage.Village_SerialNumber in (" + getCookie('village') + ")" +
                    " and natural_resources_bsm_usage.Government_Agencies_SerialNumber in (" + getCookie('unit') + ")"))),
            },
            // showDialog: true,
            DownloadData: [],
            government_agencies: [],
        }
    },
    mounted() {

    },
    methods: {
        Treedata() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/permissionsTree/getDistrictTreeByPermissions`,
                type: "GET",
                data: {
                    DistrictCode: getCookie('village'),
                },
                success: (data) => {
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${mh}/generalBusiness/generalQueryByTableName`,
                        method: "post",
                        data: {
                            Data: 'village_collective',
                            Condition: `Row_Status='0'`,
                        },
                        success: (data1) => {
                            data.forEach(item => {
                                item.children.forEach(ite => {
                                    ite.children.forEach(it => {
                                        it.children = [];
                                        data1.filter(i => i.VillageNumber == it.ProvinceNumber).forEach(i => {
                                            it.children.push({
                                                ParentNumber: i.VillageNumber,
                                                Province: i.Org_Name,
                                                ProvinceNumber: i.Village_Collective_SerialNumber,
                                                children: [],
                                            })
                                        })

                                    })
                                })
                            });
                            this.treeData = data; // 直接使用 this
                        },
                        complete: (XMLHttpRequest) => {
                            requestPretreatment(XMLHttpRequest);
                        }
                    });
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'government_agencies',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.government_agencies = data; // 直接使用 this

                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        //树的点击筛选事件
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%%,%%")));
            this.postgetList(this.page)
        },
        //树的点击筛选事件
        handleNodeClick(data, node) {
            if (node.level == 4) {
                this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%%,%" + data.ProvinceNumber + "%")));
            } else {
                this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%," + data.ProvinceNumber + "%,%%")));
            }
            this.postgetList(this.page)
        },
        show(row) {
            window.location.href = './show.html?action=Add&nodeKey=' + row.Natural_Resource_SerialNumber
        },
        handleUpload({ raw }) {
            const reader = new FileReader();
            reader.readAsText(raw);
            reader.onload = (event) => {
                try {
                    const jsonData = JSON.parse(event.target.result);
                    //处理JSON文件格式this.DownloadData = 
                    this.DownloadData = [];
                    jsonData.features.map(i => {
                        return { data: i.properties, coords: JSON.stringify(i.geometry.coordinates) }
                    }).forEach(({ data, coords }, index) => {
                        this.DownloadData.push({
                            Natural_Resource_SerialNumber: data.YSDM,
                            Natural_Resource_Name: data.TBXHMC,
                            Area: data.SHAPE_Area,
                            Natural_Resource_Usage_SerialNumber: data.DLBM,
                            Natural_Resource_Ownership_Rights: data.QSXZ,
                            Coords: coords,
                            QSDWDM: data.QSDWDM,
                            DLMC: data.DLMC,
                            QSDWMC: data.QSDWMC,
                            ZLDWMC: data.ZLDWMC,
                            TBXHMC: data.TBXHMC,
                            ZZSXMC: data.ZZSXMC,
                            TBMJ: data.TBMJ,
                            YSDM: data.YSDM,
                            DKMC: data.DKMC,
                            ZLDWDM: data.ZLDWDM,
                            Government_Agencies_SerialNumber: this.government_agencies.filter(i => i.Agensies_Name == data.QSDWMC)[0] ? this.government_agencies.filter(i => i.Agensies_Name == data.QSDWMC)[0].Government_Agencies_SerialNumber : '',
                            ZZSXDM: data.ZZSXDM,
                            Province_Number: '230000',
                            City_Number: '232700',
                            County_Nubmer: '232723',
                            Town_Number: '232723104',
                            Village_SerialNumber: '232723104201',
                        })
                    })
                    console.log('JSON文件内容:', this.DownloadData);
                } catch (error) {
                    this.$message.error('JSON文件格式不正确');
                }
            };
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
